Repository navigation
fix(plugin): run cache purge queue writes in transactions - #4305
Conversation
claim_updates_cache_purge, ack_updates_cache_purge and notify_updates_edge_cache_purge were called as bare SELECTs, which Hyperdrive can answer from its query cache without running them. In prod the throttle row was updated 13 times while the worker logged 930 purge batches in 75s: drains replayed one cached claim and purged the same apps, failed acks never applied their back-off, and enqueues could be dropped. They now run in a transaction, like plugin_state_sync's mutate(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
|
|
@coderabbitai review |
Action not completed
|



Summary
Root cause of the
/updatescache purge storm I've been chasing in prod since the #4290 release. #4303 and #4304 were needed, but they couldn't take effect because of this.The purge queue RPCs were sent as bare
SELECTs:claim_updates_cache_purgeack_updates_cache_purgenotify_updates_edge_cache_purgeHyperdrive caches
SELECTs and can answer them from its query cache without running them. These functions write (leases, the shared throttle, requeues, pending rows), so a cached answer means the write never happens.Production evidence (2026-12-01 08:2x UTC, measured together):
pg_stat_user_tables.n_tup_updonupdates_cache_purge_staterose by 13 in about 75 s. Every claim that runs updates that row.updates cache purgedbatches.Fix: the claim, ack and both enqueue calls now run inside
withPgTransaction. That's the existing pattern for queue RPCs that write (plugin_state_sync.tsmutate(), with the same comment). A transaction always reaches the database. This doesn't make a read uncacheable to dodge stale data, which AGENTS.md forbids: these calls are writes. They're one round trip per drain batch, not request-path reads.The same bare-
SELECT-of-a-writing-function pattern also exists in:begin_app_storage_cleanup_passinon_app_delete.tsdelta_gc_finishincron_delta_storage_gc.tstrack_onboarding_demo_datainpublic/app/demo.tsNot changed here, so this incident fix stays small. They're worth checking next.
Test plan
tests/updates-cache-purge-transaction.unit.test.ts: the drain's claim and the enqueue both run inside a transaction.utils/pg.tsget a pass-throughwithPgTransaction.bun run test:unit(681 files),typecheck:backend,lint:backend,lint:deadcodeupdates_cache_purge_stateupdates match logged purge batches, 429s drop, andupdates_cache_purge_pendingdrains.No rendered UI changes, so there are no screenshots.
🤖 Generated with Claude Code